SMOODEV-2513: Add connect timeout to TS fetch SDK (default-off)#92
Open
brentrager wants to merge 1 commit into
Open
SMOODEV-2513: Add connect timeout to TS fetch SDK (default-off)#92brentrager wants to merge 1 commit into
brentrager wants to merge 1 commit into
Conversation
…i dispatcher) Bounds only the connection-establishment phase so a black-holed connect (a SYN to a dead pod IP still lingering in a ClusterIP's iptables) fails fast and retry can land on a live endpoint, instead of stalling until the whole-request timeout. Node only, via a lazily-loaded undici Agent dispatcher; ignored in browser/worker builds. Default-off: unset preserves the previous behavior exactly. Parity with Rust with_connect_timeout (#88). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 22ba327 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional connect timeout to the TypeScript SmooAI fetch SDK — parity with the Rust PR #88 (
with_connect_timeout, SMOODEV-2513).RequestOptions.connectTimeoutMsoption (same options surface as the existing whole-requesttimeout: { timeoutMs }).FetchBuilder.withConnectTimeout(ms), mirroringwithTimeout(...)and the Rust builder.Why
api-prime's ~16s stalls (SMOODEV-2498 / SMOODEV-2481) were fresh SYNs to dead pod IPs still lingering in a ClusterIP's iptables. The whole-request
timeoutonly fires after the entire request budget elapses, so a black-holed connect stalls for the full window before retry can even try a live endpoint. A connect timeout bounds only the connection-establishment phase: a dead connect fails in ~the configured window and the configured retry lands on a live pod. Slow-but-alive handlers are unaffected.How
Node's global
fetchis undici under the hood. A connect timeout requires adispatcher— an undiciAgent({ connect: { timeout: ms } })— passed on the fetch init. WhenconnectTimeoutMsis set we lazily build (and cache, keyed by ms) such an Agent and attach it asdispatcher.^6to match Node 22's bundled undici handler interface (npm undici@8'sAgentis rejected by Node 22's built-in fetch withUND_ERR_INVALID_ARG/invalid onRequestStart method— a real cross-version footgun). It's imported via a guardedawait import('undici'), so it never loads unless a connect timeout is actually requested, and it stays an external dynamic import in both the node and browser builds (not bundled).Default-off (behavior-identical)
When
connectTimeoutMsis unset, no dispatcher is attached — the fetch call is byte-identical to today. The undici import is never reached. In browser/worker environments the option is ignored (no connect-timeout knob there;getConnectTimeoutDispatcherreturnsundefinedbefore importing undici).Test
src/fetch.connect-timeout.spec.tsmirrors the Rustconnect_timeout_tests.rs: a connect to the non-routable black-holehttp://10.255.255.1:80/withconnectTimeoutMs: 500and a 10x-larger whole-requesttimeoutof 5000ms fails in ~1s (well under 3s), and the error is not the mollitia whole-requestTimeoutError. Plus a builder-path test and an unset-option (default-behavior) test. All 51 TS tests pass (48 existing + 3 new); typecheck, lint, format, and both builds are green.🤖 Generated with Claude Code